package prj3.gui;
import data.Database;
import prj3.MasterControl;
import prj3.MasterControl;

public class EarthSim2
{
	Display gui = new Display();;

	
	public void run() {
		this.gui.setVisible(true);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
        int precision = 23;
        float geoPercent = 1.0f;
        float tempPercent = 1.0f;
        if(args.length % 2 != 0) {
        	System.err.println("ERROR: You need a pair number of arguments");
        	System.exit(-1);
        }
        for(int i = 0; i < args.length; i++){
            if(args[i].equals("-g")){
            	i++;
            	try {
            		geoPercent = (float)Integer.parseInt(args[i])/100.0f;
            		if(geoPercent <= 0 || geoPercent > 1)
            			throw new NumberFormatException();
            	} catch(NumberFormatException ex) {
            		System.err.println("Argument to -g should be an integer between 1 and 100");
            		System.exit(-1);
            	}
            } else if(args[i].equals("-p")){
            	i++;
            	try {
            		precision = Integer.parseInt(args[i]);
            		if(precision < 0 || precision > 23)
            			throw new NumberFormatException();
            	} catch(NumberFormatException ex) {
            		System.err.println("Argument to -p should be an integer between 0 and 23");
            		System.exit(-1);
            	}
            } else if(args[i].equals("-t")){
            	i++;
            	try {
            		tempPercent = (float)Integer.parseInt(args[i])/100.0f;
            		if(tempPercent <= 0 || tempPercent > 1)
            			throw new NumberFormatException();
            	} catch(NumberFormatException ex) {
            		System.err.println("Argument to -t should be an integer between 1 and 100");
            		System.exit(-1);
            	}
            } else {
            	System.err.println("Unknown argument: " + args[i]);
            	System.exit(-1);
            }
        }
        Database.Initialize( "francium.cc.gt.atl.ga.us", 9876, "ds3", "ds3", "EarthSim" );
        MasterControl.init((java.util.GregorianCalendar)util.Constants.startDate.clone(), tempPercent, geoPercent, precision);
        java.awt.EventQueue.invokeLater(new Runnable() {
        	public void run() {
        		new EarthSim2().run();
        	}
        });

	}

}
